#!/usr/bin/env python3

pys = ['zh', 'ch', 'sh']
output_dir = r'D:\Temp\output'
anki_import_data_file_name = 'anki_import_data.txt'

import hashlib
import os
import secrets

anki_media_dir = r'C:\Users\XYQTJ\AppData\Roaming\Anki2\User 1\collection.media'

def genAnkiImportData(file_path, pys):
    lines = []
    for index in range(len(pys)):
        py = pys[index]
        ques_part = '<font size="10">' + py + '</font><br>怎么读'
        ans_part = '[sound:' + py + '.mp3]'
        line = ques_part + "\t" + ans_part + "\n"
        print(line)
        lines.append(line)
    
    opt_part = '<br>'
    for index in range(len(pys)):
        opt_part += '<font size="10">' + str(index + 1) + ' ' + pys[index] + '</font><br>'
        
    for index in range(len(pys)):
        py = pys[index]
        ques_part = '[sound:' + py + '.mp3]' + opt_part
        ans_part = '<font size="10">' + py + '</font>'
        line = ques_part + "\t" + ans_part + "\n"
        print(line)
        lines.append(line)
    
    with open(file_path, mode="w", encoding="utf8") as file:
        file.writelines(lines)

anki_import_data_file_path = os.path.join(output_dir, anki_import_data_file_name)
genAnkiImportData(anki_import_data_file_path, pys)
